<?php

// note to self - we need to remove the locale price list as soon as the case is finished in VAS?
class LocalePriceLists extends Zend_Db_Table_Abstract
{
	protected $_name = 'locale_price_lists';
	private $_errorCode = '';
	private $_errorStr = '';
	
	public function getErrorCode() { return $_errorCode; }
	public function getErrorStr() { return $_errorStr; }
	
	public function getPriceListForLocale( $locale_id, $case_num )
	{
		$priceList = array();
		
		if(null == $locale_id || null == $case_num)
		{
			$_errorCode = 'PARAM_ERR';
			$_errorStr = 'Invalid parameter given to getPriceListForLocale';
			return null;
		}
		
		try
		{
			$r = $this->fetchAll("locale_id=$locale_id and FDMS_case_num='$case_num'");
			if($r)
			{
				foreach($r as $rr)
					$priceList[] = $rr->toArray();
			}
		}
		catch(Exception $e)
		{
			$_errorCode = 'SQL_ERR';
			$_errorStr = "".$e;
			return null;
		}
		
		return $priceList;
	}
	
	public function setPriceListForLocale( $price_list, $locale_id, $case_num )
	{
		$status = "OK";
				
		if(null == $locale_id || null == $case_num || null==$price_list || !is_array($price_list))
		{
			$_errorCode = 'PARAM_ERR';
			$_errorStr = 'Invalid parameter given to getPriceListForLocale';
			return null;
		}

		try
		{
			// delete existing price list
			$r = $this->delete("locale_id=$locale_id and FDMS_case_num='$case_num'");
			// loop thru and do insert of new price list
			foreach($price_list as $row)
			{
				$r = $this->insert( $row );
			}
		}
		catch(Exception $e)
		{
			$_errorCode = 'SQL_ERR';
			$_errorStr = "".$e;
			return null;
		}
		
		return $status;
	}
	
	public function removePriceListForLocale( $locale_id, $case_num )
	{
		$status = "OK";
				
		if(null == $locale_id || null == $case_num || null==$price_list || !is_array($price_list))
		{
			$_errorCode = 'PARAM_ERR';
			$_errorStr = 'Invalid parameter given to getPriceListForLocale';
			return null;
		}

		try
		{
			// delete existing price list
			$r = $this->delete("locale_id=$locale_id and FDMS_case_num='$case_num'");
		}
		catch(Exception $e)
		{
			$_errorCode = 'SQL_ERR';
			$_errorStr = "".$e;
			return null;
		}
		
		return $status;
	}
}

?>